package p270jp.pxv.android.legacy.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import com.google.android.gms.common.internal.ServiceSpecificExtraArgs;
import p325m0.MutabilityOwnership;

/* compiled from: RelativeRadioGroup.kt */
/* renamed from: jp.pxv.android.legacy.view.RelativeRadioGroup */
/* loaded from: classes2.dex */
public final class RelativeRadioGroup extends RelativeLayout {

    /* renamed from: a */
    public int f19098a = -1;

    /* renamed from: b */
    public final C4254a f19099b = new C4254a();

    /* renamed from: c */
    public final ViewGroup$OnHierarchyChangeListenerC4255b f19100c;

    /* renamed from: d */
    public boolean f19101d;

    /* compiled from: RelativeRadioGroup.kt */
    /* renamed from: jp.pxv.android.legacy.view.RelativeRadioGroup$a */
    /* loaded from: classes2.dex */
    public final class C4254a implements CompoundButton.OnCheckedChangeListener {
        /* JADX WARN: Incorrect args count in method signature: ()V */
        public C4254a() {
        }

        @Override // android.widget.CompoundButton.OnCheckedChangeListener
        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            MutabilityOwnership.m3745m(compoundButton, "buttonView");
            RelativeRadioGroup relativeRadioGroup = RelativeRadioGroup.this;
            if (!relativeRadioGroup.f19101d) {
                relativeRadioGroup.f19101d = true;
                if (relativeRadioGroup.getCheckedRadioButtonId() != -1) {
                    RelativeRadioGroup relativeRadioGroup2 = RelativeRadioGroup.this;
                    relativeRadioGroup2.m4590d(relativeRadioGroup2.getCheckedRadioButtonId(), false);
                }
                RelativeRadioGroup.this.f19101d = false;
                RelativeRadioGroup.this.setCheckedId(compoundButton.getId());
            }
        }
    }

    /* compiled from: RelativeRadioGroup.kt */
    /* renamed from: jp.pxv.android.legacy.view.RelativeRadioGroup$b */
    /* loaded from: classes2.dex */
    public final class ViewGroup$OnHierarchyChangeListenerC4255b implements ViewGroup.OnHierarchyChangeListener {

        /* renamed from: a */
        public ViewGroup.OnHierarchyChangeListener f19103a;

        /* JADX WARN: Incorrect args count in method signature: ()V */
        public ViewGroup$OnHierarchyChangeListenerC4255b() {
        }

        @Override // android.view.ViewGroup.OnHierarchyChangeListener
        public void onChildViewAdded(View view, View view2) {
            MutabilityOwnership.m3745m(view, "parent");
            MutabilityOwnership.m3745m(view2, "child");
            if (view == RelativeRadioGroup.this && (view2 instanceof RadioButton)) {
                if (view2.getId() == -1) {
                    view2.setId(view2.hashCode());
                }
                ((RadioButton) view2).setOnCheckedChangeListener(RelativeRadioGroup.this.f19099b);
            }
            ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener = this.f19103a;
            if (onHierarchyChangeListener != null) {
                onHierarchyChangeListener.onChildViewAdded(view, view2);
            }
        }

        @Override // android.view.ViewGroup.OnHierarchyChangeListener
        public void onChildViewRemoved(View view, View view2) {
            MutabilityOwnership.m3745m(view, "parent");
            MutabilityOwnership.m3745m(view2, "child");
            if (view == RelativeRadioGroup.this && (view2 instanceof RadioButton)) {
                ((RadioButton) view2).setOnCheckedChangeListener(null);
            }
            ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener = this.f19103a;
            if (onHierarchyChangeListener != null) {
                onHierarchyChangeListener.onChildViewRemoved(view, view2);
            }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public RelativeRadioGroup(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(attributeSet, "attrs");
        ViewGroup$OnHierarchyChangeListenerC4255b bVar = new ViewGroup$OnHierarchyChangeListenerC4255b();
        this.f19100c = bVar;
        super.setOnHierarchyChangeListener(bVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void setCheckedId(int i) {
        this.f19098a = i;
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
        MutabilityOwnership.m3745m(view, "child");
        MutabilityOwnership.m3745m(layoutParams, "params");
        if (view instanceof RadioButton) {
            RadioButton radioButton = (RadioButton) view;
            if (radioButton.isChecked()) {
                this.f19101d = true;
                int i2 = this.f19098a;
                if (i2 != -1) {
                    m4590d(i2, false);
                }
                this.f19101d = false;
                setCheckedId(radioButton.getId());
            }
        }
        super.addView(view, i, layoutParams);
    }

    /* renamed from: b */
    public final void m4592b(int i) {
        if (i == -1 || i != this.f19098a) {
            int i2 = this.f19098a;
            if (i2 != -1) {
                m4590d(i2, false);
            }
            if (i != -1) {
                m4590d(i, true);
            }
            setCheckedId(i);
        }
    }

    /* renamed from: c */
    public final void m4591c() {
        int width = getWidth();
        int childCount = getChildCount();
        if (childCount > 0) {
            int i = 0;
            int i2 = 0;
            int i3 = 0;
            int i4 = 0;
            while (true) {
                int i5 = i + 1;
                View childAt = getChildAt(i);
                int measuredWidth = childAt.getMeasuredWidth() + i2;
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
                if (i3 <= 0) {
                    i4 = childAt.getId();
                } else if (measuredWidth >= width) {
                    layoutParams.addRule(3, i4);
                    i4 = childAt.getId();
                    measuredWidth = 0;
                } else if (getChildCount() > 0) {
                    layoutParams.addRule(1, i3);
                }
                i3 = childAt.getId();
                childAt.setLayoutParams(layoutParams);
                if (i5 < childCount) {
                    i = i5;
                    i2 = measuredWidth;
                } else {
                    return;
                }
            }
        }
    }

    @Override // android.widget.RelativeLayout, android.view.ViewGroup
    public boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        MutabilityOwnership.m3745m(layoutParams, "p");
        return layoutParams instanceof RelativeLayout.LayoutParams;
    }

    /* renamed from: d */
    public final void m4590d(int i, boolean z) {
        View findViewById = findViewById(i);
        if (findViewById != null && (findViewById instanceof RadioButton)) {
            ((RadioButton) findViewById).setChecked(z);
        }
    }

    @Override // android.widget.RelativeLayout, android.view.ViewGroup
    public ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new RelativeLayout.LayoutParams(-2, -2);
    }

    public final int getCheckedRadioButtonId() {
        return this.f19098a;
    }

    @Override // android.view.View
    public void onFinishInflate() {
        super.onFinishInflate();
        int i = this.f19098a;
        if (i != -1) {
            this.f19101d = true;
            m4590d(i, true);
            this.f19101d = false;
            setCheckedId(this.f19098a);
        }
    }

    @Override // android.view.View
    public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        MutabilityOwnership.m3745m(accessibilityEvent, "event");
        super.onInitializeAccessibilityEvent(accessibilityEvent);
        accessibilityEvent.setClassName("jp.pxv.android.legacy.view.RelativeRadioGroup");
    }

    @Override // android.view.View
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        MutabilityOwnership.m3745m(accessibilityNodeInfo, "info");
        super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
        accessibilityNodeInfo.setClassName("jp.pxv.android.legacy.view.RelativeRadioGroup");
    }

    @Override // android.view.ViewGroup
    public void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener onHierarchyChangeListener) {
        MutabilityOwnership.m3745m(onHierarchyChangeListener, ServiceSpecificExtraArgs.CastExtraArgs.LISTENER);
        this.f19100c.f19103a = onHierarchyChangeListener;
    }

    @Override // android.widget.RelativeLayout, android.view.ViewGroup
    public RelativeLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        MutabilityOwnership.m3745m(attributeSet, "attrs");
        return new RelativeLayout.LayoutParams(getContext(), attributeSet);
    }
}
